<template>
  <el-card>
    <div id="container" style="min-width:400px;height:400px"></div>
  </el-card>
</template>
<script>
import { queryList } from "../api/api";
var Highcharts = require("highcharts");
require("highcharts/modules/exporting")(Highcharts);
export default {
  data() {
    return {
      totalNum: 0,
      totalDoneNum: 0
    };
  },
  methods: {
    charts() {
      //console.log(this.totalNum);
      Highcharts.chart("container", {
        chart: {
          plotBackgroundColor: null,
          plotBorderWidth: null,
          plotShadow: false,
          type: "pie"
        },
        exporting: {
          enabled: false //用来设置是否显示‘打印’,'导出'等
        },
        credits: {
          enabled: false
        },
        title: {
          text: "用户数据饼状图"
        },
        tooltip: {
          pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: "pointer",
            dataLabels: {
              enabled: true,
              format: "<b>{point.name}</b>: {point.percentage:.1f} %",
              style: {
                color:
                  (Highcharts.theme && Highcharts.theme.contrastTextColor) ||
                  "black"
              }
            }
          }
        },
        series: [
          {
            name: "Brands",
            colorByPoint: true,
            data: [
              {
                name: "已处理二维码",
                y: this.totalDoneNum,
                sliced: true,
                selected: true
              },
              {
                name: "未处理二维码",
                y: this.totalNum - this.totalDoneNum,
                color: "green"
              }
            ]
          }
        ]
      });
    }
  },
  mounted() {
    queryList({}).then(data => {
      let jsonArray = data.data.list;
      for (let json of jsonArray) {
        this.totalNum += json["allCount"];
        this.totalDoneNum += json["processedCount"];
      }
      this.charts();
    });
  }
};
</script>
